/*1、用循环解决第 3 节 “递归”的所有习题，体会递归和循环这两种不同的思路。*/
#include<stdio.h>

int return_GCD(int a, int b);
int fibona(int n);

int main()
{
    printf("GCD(-8, -12) = %d\n", return_GCD(12, 8));
    printf("fibona(4) = %d\n", fibona(4));    

    return 0;
}

int return_GCD(int a, int b)
{
    while (a % b)  /*Equivalent to a special case*/
    {
        int tmp = a; /*It's like every recursive call*/
        a = b;
        b = tmp % a;
    }

    return b > 0 ? b : -b;
}

int fibona(int n)
{
    int res = 1;
    int pre0 = 1;
    int pre1 = 1;

    while (n > 1)
    {
        res = pre0 + pre1;
        pre0 = pre1;
        pre1 = res;
        --n;
    }

    return res;
}
